package cn.wolfcode.cloud.shop.mq.listener;

import cn.wolfcode.cloud.shop.consts.MQConstants;
import cn.wolfcode.cloud.shop.mq.msg.DelayOrderMsg;
import cn.wolfcode.cloud.shop.service.IOrderInfoService;
import cn.wolfcode.cloud.shop.util.JSONUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author Administrator
 */
@Component
@RocketMQMessageListener(
    topic = MQConstants.SECKILL_ORDER_TOPIC,
    consumerGroup = MQConstants.DELAY_ORDER_CONSUMER_GROUP,
    selectorExpression = MQConstants.DELAY_ORDER_TAG
)
public class DelayOrderMQListener implements RocketMQListener<DelayOrderMsg> {

    private Logger logger = LoggerFactory.getLogger("DELAY_ORDER_MQ_LISTENER");

    @Autowired
    private IOrderInfoService orderInfoService;

    @Override
    public void onMessage(DelayOrderMsg delayOrderMsg) {
        logger.info("收到的延迟消息:{}", JSONUtil.toJsonString(delayOrderMsg));

        orderInfoService.checkOrderTimeOut(delayOrderMsg.getOrderNo(),delayOrderMsg.getUserId(),delayOrderMsg.getSeckillId());
    }
}
